package com.steven.design.XingWei_Pattern.FangWenZhe;


import com.steven.design.XingWei_Pattern.FangWenZhe.WeiPai.*;

import java.util.ArrayList;
import java.util.List;

class Restaurant {
    private String lobster = "Lobster";
    private String watermelon = "watermelon";
    private String steak = "steak";
    private String banana = "banana";

//    接口中提供了四个方法， 让顾客依次选择每种食物。
//    在餐厅中提供接收访问者的方法：
    public void welcome(IVisitor visitor) {
        visitor.chooseLobster(lobster);
        visitor.chooseWatermelon(watermelon);
        visitor.chooseSteak(steak);
        visitor.chooseBanana(banana);
    }

    // 准备当天的食物
    private List<FoodBack> prepareFoods() {
        List<FoodBack> foods = new ArrayList<>();
        // 简单模拟，
        foods.add(new Lobster());
        foods.add(new Watermelon());
        foods.add(new Steak());
        foods.add(new Banana());
        return foods;
    }

    // 欢迎顾客来访
    public void welcomeBack(IVisitorBack visitor) {
        // 获取当天的食物
        List<FoodBack> foods = prepareFoods();
        // 将食物依次提供给顾客选择
        for (FoodBack food : foods) {
            // 由于重写方法是动态分派的，所以这里会调用具体子类的 accept 方法，
            food.accept(visitor);
        }
    }

}